﻿using Prism.Mvvm;
using Prism.Regions;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;

namespace ModelA.ViewModels
{
    public class ViewAAViewModel : BindableBase, IConfirmNavigationRequest
    {
        public ViewAAViewModel()
        {

        }

        private string _title;

        public string Title
        {
            get { return _title; }
            set
            {
                _title = value;
                RaisePropertyChanged();
            }
        }


        /// <summary>
        /// 每次重新导航时，是否重用原来的实例
        /// </summary>
        /// <param name="navigationContext"></param>
        /// <returns></returns>
        public bool IsNavigationTarget(NavigationContext navigationContext)
        {
            return true;
        }

        //从当前页面导航出去
        public void OnNavigatedFrom(NavigationContext navigationContext)
        {

        }

        //从其他页面导航进来
        public void OnNavigatedTo(NavigationContext navigationContext)
        {
            if (navigationContext.Parameters.ContainsKey("Title"))
                Title = navigationContext.Parameters.GetValue<string>("Title");
        }


        public void ConfirmNavigationRequest(NavigationContext navigationContext, Action<bool> continuationCallback)
        {
            bool result = true;
            if ((MessageBox.Show("确认导航?", "提示", MessageBoxButton.YesNo) == MessageBoxResult.No))
                result = false;
            continuationCallback(result);
        }
    }
}
